<?php
//php验证码
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$checkCode = "";
for($i=0;$i<4;$i++){
    $checkCode.= dechex(rand(1, 15));
}
session_start();
$_SESSION['checkcode'] =$checkCode;
//1、后边开始画画布了。
$image1= imagecreatetruecolor(110, 30);
//$color = imagecolorallocate($image1, rand(0, 255), rand(100, 200), rand(0, 105)); //这个颜色随机的话，很难看的清除了，全体设置为白色比较好
$color = imagecolorallocate($image1,255,255,255); //这个颜色随机的话，很难看的清除了，全体设置为白色比较好

//画出干扰线
for($i=0;$i<20;$i++){
    $colorline= imagecolorallocate($image1, rand(0, 255), rand(0, 255),rand(0, 255)); 
    imageline($image1, rand(0, 110), rand(0, 30), rand(0, 110), rand(0, 30), $colorline);
}
imagestring($image1, rand(1,6), rand(0, 80), rand(0, 15), $checkCode, $color);
header("Content-type:image/png");
imagepng($image1);
imagedestroy($image1);